package cn.jekun.shop.app.action;

import javax.annotation.Resource;

import cn.jekun.component.base.bean.ErrorMsg;
import cn.jekun.component.base.exceptions.BusinessException;
import cn.jekun.shop.common.service.RewardService;
import net.sf.json.JSONObject;

/**
 * 查看奖励
 * @author twj
 *
 */
@SuppressWarnings("serial")
public class RewardAction extends AppBaseAction{
	@Resource(name = RewardService.BEAN_NAME)
	RewardService rewardService;
	/**
	 * 我的奖励
	 * @return
	 */
	public String myRewards(){
		JSONObject jsonObject = null;
		try {
			String currentPage = this.request.getParameter("currentPage");
			String pageSize = this.request.getParameter("pageSize");
			this.validateSign(this.getLoginSign(), this.getUserId());
			this.validateLoginApp();
			jsonObject = rewardService.getMyRewards(currentPage,pageSize,this.getUserId());
		} catch (BusinessException e) {
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
	/**
	 * 排行榜（列出前100名）
	 * @return
	 */
	public String ranking(){
		JSONObject jsonObject = null;
		try {
			String currentPage = "1";
			String pageSize = "100";
			this.validateSign(this.getLoginSign(), this.getUserId());
			this.validateLoginApp();
			jsonObject = this.rewardService.ranking(currentPage, pageSize, this.getUserId());
		} catch (BusinessException e) {
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		} catch (Exception e) {
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			e.printStackTrace();
		}
		return this.writeJson(jsonObject);
	}
}
